﻿//by Niratpapha@
//2/9/2010
//sampleData
/*
[
		{"fullname":"ขั้นตอนที่1","link":"test-1111111.html","shortname":"1","id":"list1"},
		{"fullname":"ขั้นตอนที่2","link":"test-1111111.html","shortname":"2","id":"list2"},
		{"fullname":"ขั้นตอนที่3","link":"test-1111111.html","shortname":"3","id":"list3"},
		{"fullname":"ขั้นตอนที่4","link":"test-1111111.html","shortname":"4","id":"list4"},
		{"fullname":"ขั้นตอนที่5","link":"test-1111111.html","shortname":"5","id":"list5"},
		{"fullname":"ขั้นตอนที่6","link":"test-1111111.html","shortname":"6","id":"list6"},
		{"fullname":"ขั้นตอนที่7","link":"test-1111111.html","shortname":"7","id":"list7"},
		{"fullname":"ขั้นตอนที่8","link":"test-1111111.html","shortname":"8","id":"list8"},
		{"fullname":"ขั้นตอนที่9","link":"test-1111111.html","shortname":"9","id":"list9"}
]

*/

// JavaScript Document
(function($) {
    jQuery.fn.twHoverMenu = function(settings) {
        var defaults = { dataURL: "twHoverMenu.txt", target:"#holder",titleLoad: "Loading list.......",messageLoad: "Please wait few second...", nameID: "menu1"}
        var options = jQuery.extend(defaults, settings);
        var holder = $(this);
		$(holder).empty();
        $.getJSON(options.dataURL, function(data) {
			$(data).each(function(i) {
				if(data[i].link != ""){
				$(holder).append('<div class="ui-state-default ui-corner-top fullname " style="padding:5px; cursor:pointer; float:left" link="'+data[i].link+'" id="' + data[i].id + '">'+data[i].fullname+"</div>")
				$(holder).append('<div class="ui-state-default ui-corner-top shortname" style="padding:5px; cursor:pointer; float:left; text-align:center" >'+data[i].shortname+"</div>")
				}else{
				$(holder).append('<div class="ui-state-disabled ui-corner-top fullname " style="padding:5px; cursor:none; float:left"  " id="' + data[i].id + '">'+data[i].fullname+"</div>")
				$(holder).append('<div class="ui-state-disabled ui-corner-top shortname" style="padding:5px; cursor:none; float:left; text-align:center" >'+data[i].shortname+"</div>")
				}
			})
			twHoverMenu(holder,options.target,options.titleLoad,options.messageLoad, options.nameID)
		})
		
        function twHoverMenu(holder,target,titleLoad,messageLoad, nameID) {
			$(holder).find("div.fullname").hide()
			
		/*$(holder).find(".shortname:not(.ui-state-disabled)").hover(function(){
				$(this).siblings(".fullname:not(.ui-state-focus)").hide().next(".shortname").show()
				$(this).prev(".fullname").show().addClass("ui-state-hover").next(".shortname").hide()	
				
			});*/
			
			//edit 1/12/2010
			
			$(holder).find(".shortname:not(.ui-state-disabled)").hover(function(){
				$(this).siblings(".fullname:not(.ui-state-focus)").hide().next(".shortname").show();
				$(this).prev(".fullname").show().addClass("ui-state-hover").next(".shortname").hide();
				
				$(holder).find(".fullname.ui-state-hover").unbind("mouseout").bind("mouseout",function(){
					$(this).hide().next(".shortname").show();
				})
			})
			
			 
			
			//end edit 1/12/2010
			$(holder).find(".fullname:not(.ui-state-disabled)").click(function(){
				
				
				$(this).siblings(".fullname").hide().siblings(".shortname").show()
				$(this).removeClass("ui-state-hover").siblings().removeClass("ui-state-focus");
				$(this).addClass("ui-state-focus").next(".shortname").addClass("ui-state-focus").hide();
				$(this).unbind("mouseout");
				var isUrl = $(this).attr("link");
					$("body").block({//block ui
						theme:     true, // true to enable jQuery UI support 
						title:    titleLoad,  // only used when theme == true 
						message:  messageLoad
					});
					$(target).load(isUrl,function(){
						$("body").unblock();	
					})					
			})
			
			
           	$(holder).find("#" + nameID).click()
			$(holder).find("#" + nameID).show(".fullname")
			$(holder).find("#" + nameID).next().hide(".shortname")
			
			
		}
	}
	
/*    jQuery.fn.twHoverMenu = function(settings) {
        var defaults = { dataURL: "twHoverMenu.txt", target:"#holder",titleLoad: "Loading list.......",messageLoad: "Please wait few second...", nameID: "menu1"}
        var options = jQuery.extend(defaults, settings);
        var holder = $(this);
        $.getJSON(options.dataURL, function(data) {
			$(data).each(function(i) {
				$(holder).append('<div class="ui-state-default ui-corner-top fullname " style="padding:5px; cursor:pointer; float:left" link="'+data[i].link+'" id="' + data[i].id + '">'+data[i].fullname+"</div>")
				$(holder).append('<div class="ui-state-default ui-corner-top shortname" style="padding:5px; cursor:pointer; float:left; text-align:center" >'+data[i].shortname+"</div>")
				if(data[i].link == ""){
					var nex = $(this).next()
					alert(nex)
				}
			})
			twHoverMenu(holder,options.target,options.titleLoad,options.messageLoad, options.nameID)
		})
		
        function twHoverMenu(holder,target,titleLoad,messageLoad, nameID) {
			
			$(holder).find("div.fullname").hide()
			$(holder).find(".shortname").hover(function(){
													  
				$(this).siblings(".fullname:not(.ui-state-focus)").hide().next(".shortname").show()
				$(this).prev(".fullname").show().addClass("ui-state-hover").next(".shortname").hide()
			})		
			$(holder).find(".fullname").click(function(){
				$(this).siblings(".fullname").hide().siblings(".shortname").show()
				$(this).siblings().removeClass("ui-state-focus")
				$(this).addClass("ui-state-focus").next(".shortname").addClass("ui-state-focus").hide()
				
				//var aa = $(this).next().addClass("ui-state-highlight")
				
				var isUrl = $(this).attr("link");
					$("body").block({//block ui
						theme:     true, // true to enable jQuery UI support 
						title:    titleLoad,  // only used when theme == true 
						message:  messageLoad
					});
					$(target).load(isUrl,function(){
						$("body").unblock();	
					})					
			})
           	$(holder).find("#" + nameID).click()
			$(holder).find("#" + nameID).show(".fullname")
			$(holder).find("#" + nameID).next().hide(".shortname")
		}
	}
*/})(jQuery);